package com.newegg.whois.util;

import java.util.Map;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

public class RestTemplateUtil {
	
	static RestTemplate template = new RestTemplate();

	public static String get(String url) {
		try {
			ResponseEntity<String> response = template.getForEntity(url, String.class);
			return response.getBody();
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println(url);
		}
		return null;
	}
	
	@SuppressWarnings("unchecked")
	public static Map<String, Object> getJsonMap(String url) {
		try {
			@SuppressWarnings("rawtypes")
			ResponseEntity<Map> response = template.getForEntity(url, Map.class);
			return response.getBody();
		} catch (Exception e) {
			throw e;
		}
	}
	
	public static void main(String[] args) {
		Map<String, Object> data = getJsonMap("http://localhost:9000/query?domain=www.geekcode.com.cn&force=true");
		data.forEach((k, v) ->{
			System.out.println(k + " : " + v);
		});
	}
}
